#include "devicedetaildialog.h"
#include "ui_devicedetaildialog.h"
#include "DeviceInstanceSet.h"
#include "RegionInstanceSet.h"

DeviceDetailDialog::DeviceDetailDialog(QWidget *parent) :
    BaseDialog(parent),
    ui(new Ui::DeviceDetailDialog)
{
    ui->setupUi(this);
	ui->declarativeView_cpu->setSource(QUrl::fromLocalFile("qml/cpu_curve.qml"));
	ui->declarativeView_flow->setSource(QUrl::fromLocalFile("qml/flow_curve.qml"));
	ui->declarativeView_cpu->show();
	ui->declarativeView_flow->show();
}

DeviceDetailDialog::~DeviceDetailDialog()
{
    delete ui;
}

void DeviceDetailDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

bool DeviceDetailDialog::SetEditObject(BaseObject* pEditObject, DbObjects* pEditObjects, OperationKind okAction)
{
    BaseDialog::SetEditObject(pEditObject, pEditObjects, okAction);

    Device1* pDevice = (Device1*)pEditObject;
    Devices* pDevices = (Devices*)pEditObjects;
    Regions* pRegions = g_pRegionInstanceSet->GetRegions();
    GraphicModels* pGraphicModels = g_pDeviceInstanceSet->GetGraphicModels();
    if(NULL == pDevice
       || NULL == pDevices
       || NULL == pRegions
       || NULL == pGraphicModels)
    {
        close();
        return false;
    }
    ui->lblName->setText(pDevice->GetName());
    ui->lblCorp->setText(pRegions->GetNameByID(pDevice->GetCorpID().toUInt()));
    ui->lblPlatformType->setText(pGraphicModels->GetPlatformNameByCode(pDevice->GetPlatformCode()));
    ui->lblIP->setText(pDevice->GetIP());
    ui->lblUpdateTime->setText(pDevice->GetAddTime());
    ui->lblArea->setText(pDevice->GetArea());
    ui->lblOwner->setText(pDevice->GetOwner());
    ui->lblFetchIP->setText(pDevice->GetIPFetch());
    ui->lblFactory->setText(pDevice->GetFactory());
    ui->lblLinkLib->setText(pDevice->GetCommunity());
    ui->lblVoltageLevel->setText(pDevice->GetVoltageLevel());
    ui->lblCPU->setText(pDevice->GetCPU());
    ui->lblModel->setText(pDevice->GetModel());
    ui->lblMEM->setText(pDevice->GetMEM());
    ui->lblVersion->setText(pDevice->GetVersion());
    ui->lblRemark->setText(pDevice->GetRemark());
    this->setStyleSheet("background-color: rgb(255, 255, 255)");
    return true;
}
